import configs from "@/config/index.config.js";
export  default{  
  showLoading(title,icon='loading') {
    uni.showLoading({
      title: title,
      icon: icon
    })
  },
  showToast(title){
    uni.showToast({
      title: title,
      icon: 'none'
    })
  },
   //上传图片
   uploadFn(type) {
     console.log(type,'type')
     return new Promise((resolve,reject)=>{
      uni.chooseImage({
        count: 1, // 图片数量-----默认9
        sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
        sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
        success: (chooseImageRes) => {
          const tempFilePaths = chooseImageRes.tempFilePaths;
          console.log(tempFilePaths,'tempFilePaths')
          uni.showLoading({
            title: '开始上传',
            icon: 'none',
          });
          // showLoading('开始上传')
          uni.uploadFile({
            url: configs.baseUrl + '/usercenter/UserInfo/upload', //仅为示例，非真实的接口地址
            name: 'file',
            header: {
              'Content-type': 'multipart/form-data',
              'Authorization':'Bearer '+ uni.getStorageSync("token")
            },
            filePath: tempFilePaths[0],
            success: (uploadFileRes) => {
             
              if(uploadFileRes.statusCode==200){
                let data=JSON.parse(uploadFileRes.data)
                data.data.url=configs.imgUrl+data.data.url
                console.log(data,'获取图片')
                resolve(data)
              }
              
              uni.hideLoading();
              // this.toastFn('上传成功')
              // uni.hideLoading();
              // let imgList = this.imgList;
              // imgList.push(JSON.parse(uploadFileRes.data).data.url)
              // this.imgList = imgList;
            },
            fail:(err)=>{
              reject(err)
              uni.hideLoading();
            }
          });
        }
      });
     })
    
  },

}